#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define NMAX 100000

typedef struct Vector {
	unsigned int *data;
	int n, size;
} Vector;

void
Init(Vector *v)
{
	v->n = 0;
	v->size = 2;
	v->data = (unsigned int*)malloc(v->size * sizeof(unsigned int));
	if (v->data == NULL)
		fprintf(stderr, "Init(): Out of memory\n");
}

void
Append(Vector *v, unsigned int key)
{
	if (v->n >= v->size) { /* v->n will increase */
		v->size *= 2;
		v->data = (unsigned int*)realloc(v->data, v->size * sizeof(unsigned int));
	}
	v->data[v->n++] = key;
}

int
main(int argc, char **argv)
{
	int n;
	Vector **vptr = NULL;
	int i, j;
	short cmd;
	unsigned int key;
	register int k = 0;

	(void) freopen("database.in", "r", stdin);
	(void) freopen("database.out", "w", stdout);

	(void)scanf("%d", &n);
	vptr = (Vector**)malloc(n * sizeof(Vector*));
	if (vptr == NULL) {
		printf("main(): Out of memory\n");
		return (1);
	}

	for (k=0 ; k < n ; ++k) {
		vptr[k] = (Vector*)malloc(sizeof(Vector));
		Init(vptr[k]);
		if (vptr[k] == NULL)
			printf("main(): Out of memory (vptr[%d], %lu)\n", k, sizeof(Vector));
	}

	while (scanf("%hd", &cmd) == 1) {
		if (cmd == 1) {
			(void) scanf("%d%u", &i, &key);
			if (i <= 0 || i > n) {
				printf("-1\n");
				continue;
			}
			Append(vptr[i-1], key);
		} else if (cmd == 2) {
			(void) scanf("%d%d", &i, &j);
			if (i <= 0 || i > n || vptr[i-1]->n < j
					|| j <= 0)
				printf("-2\n");
			else
				printf("%d\n", vptr[i-1]->data[j-1]);
		} else if (cmd == 3)
			break;
	}

	for (k = 0 ; k < n ; ++k) {
		free(vptr[k]->data);
		free(vptr[k]);
	}
	free(vptr);

	return (0);
}
